package com.sfx.controller;

import com.sfx.domain.ResponseResult;
import com.sfx.domain.entity.User;
import com.sfx.enums.AppHttpCodeEnum;
import com.sfx.exception.SystemException;
import com.sfx.service.BlogLoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        String userName = user.getUserName();
        String password = user.getPassword();
        if(StringUtils.isAnyBlank(userName,password)) {
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME_PASSWORD);
        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout() {
        return blogLoginService.logout();
    }
}